package com.weixing.mall.provider.controller.sys;


import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoRepeatSubmit;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.model.domain.User;
import com.weixing.mall.provider.model.dto.sys.CustomerAppdepotDto;
import com.weixing.mall.provider.model.dto.sys.SysDictDto;
import com.weixing.mall.provider.model.query.CustomerAppdepotQuery;
import com.weixing.mall.provider.model.query.SysDictQuery;
import com.weixing.mall.provider.model.vo.sys.SysUserRoleVo;
import com.weixing.mall.provider.service.ICustomerAppdepotService;
import com.weixing.mall.provider.support.constant.CmsConst;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * APP仓库与客服人员的绑定关系 前端控制器
 *
 * @author Small
 * @since 2021-08-04
 */
@RestController
@RequestMapping("/customerAppdepot")
@Api(value = "客服仓库人员绑定APi", tags = "客服仓库人员绑定")
public class CustomerAppdepotController extends BaseController {
    @Autowired
    private ICustomerAppdepotService customerAppdepotService;

    @ApiOperation(value = "加载列表")
    @GetMapping("")
    public Result list(CustomerAppdepotQuery customerAppdepotQuery) {
        return ResultUtil.success(customerAppdepotService.selectOfPage(initMpPage(),customerAppdepotQuery));
    }



    @ApiOperation(value = "修改内容回显")
    @GetMapping("getById/{id}")
    public Result getById(@PathVariable Long id) {
        return ResultUtil.success(customerAppdepotService.getById(id));
    }
    @NoRepeatSubmit
    @ApiOperation(value = "保存绑定关系")
    @PostMapping("save")
    public Result save(@Validated CustomerAppdepotDto customerAppdepotDto) {
       String msg=   customerAppdepotService.checkRepeat(customerAppdepotDto);
       if(null!=msg){
           return ResultUtil.error(msg);
       }
        customerAppdepotService.save(customerAppdepotDto);
        return ResultUtil.success();
    }

    @ApiOperation(value = "删除绑定关系")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "字典id", paramType = "path", dataType = "long")
    })
    @GetMapping("del/{id}")
    public Result del(@PathVariable long id) {
        return customerAppdepotService.removeById(id) ? ResultUtil.success() : ResultUtil.error();
    }

    @ApiOperation(value = "客服下拉列表")
    @GetMapping("/cuntomer")
    public Result cuntomerList() {
        List<SysUserRoleVo> sysUserList = customerAppdepotService.userListByCode(CmsConst.CUSTOMER_CODE);
        return ResultUtil.success(sysUserList);
    }

    @ApiOperation(value = "APP仓库下拉列表")
    @GetMapping("/appDpoot")
    public Result appDpootList() {
        List<SysUserRoleVo> sysUserList = customerAppdepotService.userListByCode(CmsConst.APP_CODE);
        return ResultUtil.success(sysUserList);
    }
}
